package com.longdaji.decoration.ui.activitiesOfMine.pendingEvaluated;

import com.longdaji.decoration.base.RxPresenter;
import com.longdaji.decoration.bean.Account;
import com.longdaji.decoration.bean.Orders;
import com.longdaji.decoration.data.DataManager;
import com.longdaji.decoration.data.network.CommonSubscriber;
import com.longdaji.decoration.utils.RxUtil;

import javax.inject.Inject;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Kanade on 2018/5/9 0009.
 */

public class OrderDetailPresenter extends RxPresenter<OrderDetailContract.IView> implements OrderDetailContract.IPresenter {
    private DataManager mDataManager;

    @Inject
    public OrderDetailPresenter(DataManager dataManager) {
        this.mDataManager = dataManager;
    }

    @Override
    public void initOrder(String orderNo) {
        addSubscribe(mDataManager.doGetOrderApi(Account.getInstance().getUserid(), null, orderNo)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxUtil.<Orders>handleResult())
                .subscribeWith(new CommonSubscriber<Orders>() {
                    @Override
                    public void onSuccess(Orders orders) {
                        mView.showInitOrder(orders.getOrders().getOrder().get(0));
                    }

                    @Override
                    public void onFailed(String msg) {

                    }
                }));
    }
}
